//
//  LGBallDetailFollowRecordCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/25.
//

#import "LGFollowRecordCell.h"
#import "LGBallDetailFollowRecordView.h"
@interface LGFollowRecordCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *dateButton;
/**   */
@property (nonatomic , strong)UIButton *editButton;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)LGBallDetailFollowRecordView *optionView;
/**   */
@property (nonatomic , strong)LGBallDetailFollowRecordView *planView;
/**   */
@property (nonatomic , strong)LGBallDetailFollowRecordView *focusView;

@end
@implementation LGFollowRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}
-(void)setType:(NSString *)type{
    _type = type;
    self.dateButton.frame = CGRectMake(viewPix(29), viewPix(8), viewPix(150), viewPix(20));

    if([type isEqualToString:@"top"]){
        self.baseView.layer.cornerRadius = 15;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(2));
            make.bottom.equalTo(self.contentView).offset(viewPix(15));
        }];
        self.dateButton.frame = CGRectMake(viewPix(29), viewPix(12), viewPix(150), viewPix(20));
        
    }else if ([type isEqualToString:@"middle"]){
        self.baseView.layer.cornerRadius = 0;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(-viewPix(2));
            make.bottom.equalTo(self.contentView).offset(viewPix(2));
        }];
    }else if ([type isEqualToString:@"bottom"]){
        self.baseView.layer.cornerRadius = 15;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(-viewPix(15));
            make.bottom.equalTo(self.contentView).offset(-viewPix(0));
        }];
    }else{
        self.baseView.layer.cornerRadius = 15;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(2));
            make.bottom.equalTo(self.contentView).offset(-viewPix(2));
        }];
    }
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.dateButton setTitle:LGNSString(dataDic[@"followup_date"]) forState:UIControlStateNormal];
    self.titleLabel.text = LGNSString(dataDic[@"remarks"]);
    self.optionView.content = LGNSString(dataDic[@"opinion"][@"content"]);
    self.planView.content = LGNSString(dataDic[@"plan_adjustment"][@"content"]);
    self.focusView.content = LGNSString(dataDic[@"next_follow"][@"content"]);
    self.optionView.recordArray = dataDic[@"opinion"][@"voices"];
    self.planView.recordArray = dataDic[@"plan_adjustment"][@"voices"];
    self.focusView.recordArray = dataDic[@"next_follow"][@"voices"];
    NSString *opinionString = LGNSString(dataDic[@"opinion"][@"content"]);
    NSString *planString = LGNSString(dataDic[@"plan_adjustment"][@"content"]);
    NSString *focusString = LGNSString(dataDic[@"next_follow"][@"content"]);
    NSArray *opinionArray = dataDic[@"opinion"][@"voices"];
    NSArray *planArray = dataDic[@"plan_adjustment"][@"voices"];
    NSArray *focusArray = dataDic[@"next_follow"][@"voices"];
    
    if(opinionString.length == 0 && opinionArray.count == 0){
        self.optionView.hidden = YES;
        [self.planView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.optionView.mas_bottom).offset(viewPix(0));
        }];
    }else{
        self.optionView.hidden = NO;
        [self.planView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.optionView.mas_bottom).offset(viewPix(8));
        }];
    }
    
    if(planString.length == 0 && planArray.count == 0){
        self.planView.hidden = YES;
        [self.focusView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.planView.mas_bottom).offset(viewPix(0));
        }];
    }else{
        self.planView.hidden = NO;
        [self.focusView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.planView.mas_bottom).offset(viewPix(8));
        }];
    }
    
    if(focusString.length == 0 && focusArray.count == 0){
        self.focusView.hidden = YES;
        [self.focusView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(viewPix(0));
        }];
    }else{
        self.focusView.hidden = NO;
        [self.focusView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(-viewPix(8));
        }];
    }
}

//去修改
-(void)editButtonTouched{
    if (self.delegate && [self.delegate respondsToSelector:@selector(reviseFollowUpRecord:)]) {
        [self.delegate reviseFollowUpRecord:LGNSString(self.dataDic[@"followup_id"])];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.dateButton];
    [self.contentView addSubview:self.editButton];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.optionView];
    [self.contentView addSubview:self.planView];
    [self.contentView addSubview:self.focusView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(5));
        make.bottom.equalTo(self.contentView).offset(viewPix(5));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.centerY.equalTo(self.dateButton);
        make.width.equalTo(@(viewPix(70)));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.top.equalTo(self.dateButton.mas_bottom).offset(viewPix(8));
    }];
    [self.optionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(8));
        make.left.right.equalTo(self.baseView);
        make.height.equalTo(@(0));
    }];
    [self.planView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.optionView.mas_bottom).offset(viewPix(8));
        make.left.right.equalTo(self.baseView);
        make.height.equalTo(@(0));
    }];
    [self.focusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.planView.mas_bottom).offset(viewPix(8));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
        make.left.right.equalTo(self.baseView);
        make.height.equalTo(@(0));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}
-(UIButton *)dateButton{
    if(!_dateButton){
        _dateButton = [UIButton buttonWithTitle:@"" titleFont:LGFont(14) textColor:@"#666666" imageName:@"药球患者-时钟"];
        _dateButton.frame = CGRectMake(viewPix(29), viewPix(8), viewPix(150), viewPix(20));
        _dateButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _dateButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        _dateButton.userInteractionEnabled = NO;
    }
    return _dateButton;
}
-(UIButton *)editButton{
    if(!_editButton){
        _editButton = [UIButton buttonWithTitle:@" " titleFont:LGFont(14) textColor:@"#666666" imageName:@"grayTip12"];
        _editButton.bounds = CGRectMake(0, 0, viewPix(70), viewPix(20));
        _editButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_editButton addTarget:self action:@selector(editButtonTouched) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editButton;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(LGBallDetailFollowRecordView *)optionView{
    if(!_optionView){
        _optionView = [[LGBallDetailFollowRecordView alloc] init];
        _optionView.title = @"本次意见";
        
    }
    return _optionView;
}

-(LGBallDetailFollowRecordView *)planView{
    if(!_planView){
        _planView = [[LGBallDetailFollowRecordView alloc] init];
        _planView.title = @"方案调整";
    }
    return _planView;
}

-(LGBallDetailFollowRecordView *)focusView{
    if(!_focusView){
        _focusView = [[LGBallDetailFollowRecordView alloc] init];
        _focusView.title = @"下次关注";
    }
    return _focusView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
